﻿Imports System
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.IO
Imports System.Xml.Serialization
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Imports System.Threading

Public Class ProjectItem
    Inherits Item
    Implements IItemWrapper(Of Project)
    Implements IWorkItemContainer

#Region " Values "

    Private m_Value As Project

#End Region

#Region " Propertys "

    Public Property Value() As Project Implements IItemWrapper(Of Project).Value
        Get
            Return m_Value
        End Get
        Set(ByVal value As Project)
            If Not m_Value Is value Then
                m_Value = value
                OnPropertyChanged("Value")
            End If
        End Set
    End Property

    ''' <summary>
    ''' Accessor for all of the Item's parents
    ''' </summary>
    Public Overloads ReadOnly Property WorkItems() As Collection(Of Item) Implements IWorkItemContainer.WorkItems
        Get
            Dim selection As New Collection(Of Item)
            For Each rel In Relationships
                If rel.RelationshipType = RelationshipType.ChildWorkItem Then
                    selection.Add(rel.RelationTo)
                End If
            Next
            Return selection
        End Get
    End Property

#End Region

    Public Sub New(ByVal Project As Project)
        MyBase.New(ItemType.Project, Project.Uri.ToString, Project.Name)
        Me.m_Value = Project
    End Sub

#Region "WorkItems"

    'Private Sub GetWorkItems_DoWork()
    '    '  Application.WorkItemStore.Query("")
    '    If Application.SelectedWITs.Count > 0 Then
    '        Dim qry As New System.Text.StringBuilder
    '        qry.Append("SELECT [System.Id], [System.Title] ")
    '        qry.Append("FROM WorkItems ")
    '        qry.Append("WHERE ")
    '        qry.Append("(")
    '        Dim IsFirst As Boolean = True
    '        For Each x In Application.SelectedWITs
    '            If Not IsFirst Then qry.Append("OR ")
    '            qry.Append("[System.WorkItemType] = 'Change Request'  ")
    '            IsFirst = False
    '        Next
    '        qry.Append(")  ")
    '        If Value.IsIterationNode Then
    '            qry.Append("AND  [System.IterationID] = '" & Value.Id & "' ")
    '        Else
    '            qry.Append("AND  [System.AreaID] = '" & Value.Id & "' ")
    '        End If
    '        qry.Append("ORDER BY [System.Id]")
    '        Debug.Write("TFS Query: " & qry.ToString)
    '        WorkItems = Application.SelectedProject.Store.Query(qry.ToString)
    '    End If
    'End Sub

#End Region


End Class
